#include "pub.h"
#include "allinit.h"

#include <WiFiMulti.h>
void httppub(double tem, double hum,double light,double rain, double water)
{   
   

    char req[512];
    sprintf(req, "http://192.168.43.219:8091/esp/sendTopi?humi=%.2f&temp=%.2f&light=%.2f&rain=%.2f&water=%.2f&name=esp1", hum,tem,light,rain,water);
    Serial.println(req);
    Serial.println(rain);
    Serial.println(water);
    Serial.println(light);

    HTTPClient http;

    //Serial.print("[HTTP] begin...\n");
    // configure traged server and url
    //http.begin("https://www.howsmyssl.com/a/check", ca); //HTTPS
    http.begin(req); //HTTP

    //Serial.print("[HTTP] GET...\n");
    // start connection and send HTTP header
    int httpCode = http.GET();

    // httpCode will be negative on error
    if (httpCode > 0)
    {
        // HTTP header has been send and Server response header has been handled
        // Serial.printf("[HTTP] GET... code: %d\n", httpCode);

        // file found at server
        if (httpCode == HTTP_CODE_OK)
        {
            String payload = http.getString();
            Serial.println(payload);
        }
    }
    else
    {
        Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
    }

    http.end();
}
void httppub(int rainress)
{   
   

    char res[128];
    sprintf(res, "http://192.168.43.219:8091/esp/sendTopi?rainincrease=%d&name=esp1",rainress );
    Serial.println("rainre");
    Serial.println(res);

    HTTPClient http;

    //Serial.print("[HTTP] begin...\n");
    // configure traged server and url
    //http.begin("https://www.howsmyssl.com/a/check", ca); //HTTPS
    http.begin(res); //HTTP

    //Serial.print("[HTTP] GET...\n");
    // start connection and send HTTP header
    int httpCode = http.GET();

    // httpCode will be negative on error
    if (httpCode > 0)
    {
        // HTTP header has been send and Server response header has been handled
        // Serial.printf("[HTTP] GET... code: %d\n", httpCode);

        // file found at server
        if (httpCode == HTTP_CODE_OK)
        {   

            String payload = http.getString();
            Serial.println(payload);
        }
    }
    else
    {
        Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
    }

    http.end();
    digitalWrite(RGB_G_PIN,LOW);
    delay(100);
    digitalWrite(RGB_G_PIN,HIGH);
}

